/*
 * @Description:
 * @Author: zhaolei
 * @Date: 2023-05-25 15:10:40
 */
import {
  BROADCAST_TYPE,
  BROADCAST_TYPE_LIST,
  ARTICLE_STATUS_LIST,
} from '@/const/type';
export const tableOption = (flag = false) => {
  return {
    ...window.$crudMixins.tableOptions,
    addBtn: false,
    editBtn: false,
    delBtn: false,
    menuWidth: 80,
    searchLabelWidth: 130,
    labelWidth: 130,
    viewBtn: false,
    emptyBtn: false,
    submitBtn: false,
    detail: flag,
    row: true,
    column: [
      {
        label: '文章标题',
        prop: 'title',
        row: true,
        rules: [
          {
            required: true,
            message: '请输入文章标题',
          },
          {
            min: 1,
            max: 25,
            message: '长度不能超过25个字符',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '关联账号',
        remote: true,
        prop: 'userPhone',
        row: true,
        type: 'select',
        filterable: true,
        clearable: true,
        dicUrl: `/app/appuser/list/official?param={{key}}`,
        props: {
          label: 'nickname',
          value: 'phone',
        },
        typeformat(item, label, value) {
          return `${item[label]}（${item[value]}）`;
        },
        rules: [
          {
            required: true,
            message: '请选择关联账号',
          },
        ],
      },
      {
        label: '文章标签',
        prop: 'label',
        row: true,
        type: 'select',
        dicUrl: '/admin/dict/type/article_tag',
        multiple: true,
        rules: [
          {
            required: true,
            message: '请选择文章标签',
          },
        ],
      },
      {
        label: '素材类型',
        prop: 'fileType',
        type: 'radio',
        row: true,
        span: 12,
        dicData: BROADCAST_TYPE_LIST,
        rules: [
          {
            required: true,
            message: '请选择素材类型',
          },
        ],
        control: (val, form) => {
          if (val === BROADCAST_TYPE.PICTURE) {
            return {
              petPicture: {
                display: true,
              },
              petVideo: {
                display: false,
              },
            };
          } else {
            return {
              petPicture: {
                display: false,
              },
              petVideo: {
                display: true,
              },
            };
          }
        },
      },
      {
        label: '',
        display: true,
        prop: 'petPicture',
        type: 'upload',
        // listType: 'picture-img',
        listType: 'picture-card',
        fileSize: 10 * 1024,
        fileType: 'img', //img/video/audio
        propsHttp: {
          name: 'hash',
          url: 'key',
        },
        multiple: true,
        oss: 'qiniu',
        cropperOption: {
          // autoCropWidth: 187.5,
          // autoCropHeight: 250,
          enlarge: 2,
          fixed: true,
          fixedNumber: [0.75, 1], // 截图框的宽高比例
        },
        tip: '请上传jpg/png/jpeg/webp/heic类型的文件，且大小不超过10M，最多可上传9张图片',
        row: true,
        span: 24,
        limit: 9,
        accept: '.jpg,.png,.jpeg,.webp,.heic',
        rules: [{ required: true, message: '请上传宣传图片', trigger: 'blur' }],
      },
      {
        label: '',
        prop: 'petVideo',
        type: 'upload',
        fileSize: 50 * 1024, // 写在这里直接拦截没有提示
        // listType: 'picture-card',
        listType: 'picture-img',
        fileType: 'video', //img/video/audio
        propsHttp: {
          name: 'hash',
          url: 'key',
        },
        oss: 'qiniu',
        tip: '视频时长仅支持3分钟以内，建议优先9-30秒，最多可上传1个视频',
        row: true,
        span: 24,
        accept: '.mp4, .mpeg, .WMV, .mov',
        limit: 1,
        rules: [{ required: true, message: '请上传宣传视频', trigger: 'blur' }],
      },
      {
        label: '文章内容',
        prop: 'content',
        type: 'textarea',
        maxlength: 2000,
        minRows: 7,
        showWordLimit: true,
        span: 24,
        rules: [{ required: true, message: '请输入文章内容', trigger: 'blur' }],
      },
      {
        type: 'select',
        label: '文章状态',
        prop: 'status',
        dicData: ARTICLE_STATUS_LIST,
        display: flag,
      },
      {
        label: '点击量',
        prop: 'clickQty',
        display: flag,
      },
      {
        label: '点赞量',
        prop: 'likeQty',
        display: flag,
      },
      {
        label: '创建时间',
        prop: 'createTime',
        type: 'datetime',
        width: 160,
        format: 'yyyy-MM-dd HH:mm:ss',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        searchRange: true,
        display: flag,
      },
      {
        label: '发布时间',
        prop: 'releaseTime',
        type: 'datetime',
        width: 160,
        format: 'yyyy-MM-dd HH:mm:ss',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        display: flag,
      },
    ],
  };
};
